#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

int kthFactor(int n, int k) {
    int count = 0;
    for (int i = 1; i <= n; i++)
        if (n % i == 0)
        {
            count++;
            if (count == k)
                return i;
        }

    return -1;
}

int kthFactor(int n, int k) {
    int count = 0,i;
    for (i = 1; i <= n / i; i++)
        if (n % i == 0)
        {
            count++;
            if (count == k)
                return i;
        }
    i--;
    if (i * i == n)  i--;
    while (i > 0)
    {
        if (n % i == 0)
        {
            count++;
            if (count == k)
                return n / i;
        }
        i--;
    }

    return -1;
}